package ar.edu.uba.fi.jmit.monitorengine.core;

import ar.edu.uba.fi.jmit.integrationcommons.Event;
import ar.edu.uba.fi.jmit.integrationcommons.EventPriority;
import ar.edu.uba.fi.jmit.monitorengine.Constants;
import ar.edu.uba.fi.jmit.monitorengine.MonitorEngineTestCase;
import ar.edu.uba.fi.jmit.monitorengine.ResourceProperties;
import ar.edu.uba.fi.jmit.monitorengine.core.monitormanager.StatelessTypeManager;
import ar.edu.uba.fi.jmit.monitorengine.exception.MonitorEngineException;
import ar.edu.uba.fi.jmit.monitorengine.mock.MockMonitor1;

public class StatelessTypeManagerTestCase extends MonitorEngineTestCase {

	public void testGetMonitor() {
		StatelessTypeManager manager = new StatelessTypeManager();
		MockMonitor1.restart();
		try {
			Event event = createEvent();
			MockMonitor1 monitor = (MockMonitor1) manager.getMonitor(MockMonitor1.class.getName(), event);
			assertNotNull(monitor);
			monitor.doExecute(event);
			assertEquals(1, MockMonitor1.getExecutedEvents().size());
			MockMonitor1 monitor2 = (MockMonitor1) manager.getMonitor(MockMonitor1.class.getName(), event);
			assertNotSame(monitor, monitor2);
		} catch (MonitorEngineException e) {
			fail(e);
		}
	}

	private Event createEvent() {
		Event event = new Event();
		event.setSource("StatelessTypeManagerTestCase");
		event.setPriority(EventPriority.NORMAL);
		event.addData(ResourceProperties.getProperty(Constants.EVENT_MONITOR_NAME_KEY), "monitorName1");
		return event;
	}
}
